class SPListExtractor {
    constructor() {
        document.title += " SPListExtractor is active";
    }

    static getFirst(arr) {
        for (var prop in arr)
            if (arr.propertyIsEnumerable(prop))
                return prop;
    }

    static isFunction(functionToCheck) {
        var getType = {};
        return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
    }

    static validateEmail(email) {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    }

    //#region Dynamic loading
    static loadjsfile(filename) {
        var fileref = document.createElement('script')
	    fileref.setAttribute("type", "text/javascript")
	    fileref.setAttribute("src", filename)
	    if (typeof fileref != "undefined")
            document.getElementsByTagName("head")[0].appendChild(fileref)
	}

    static loadScript(url, callback) {
        var script = document.createElement("script")
	    script.type = "text/javascript";

        if (script.readyState) { //IE
            script.onreadystatechange = function () {
                if (script.readyState == "loaded" || script.readyState == "complete") {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        } else { //Others
            script.onload = function () {
                callback();
            };
        }

        script.src = url;
        document.getElementsByTagName("head")[0].appendChild(script);
    }

    static loadcssfile(filename) {
        if (document.createStyleSheet) {
            document.createStyleSheet(filename);
        }
        else {
            var fileref = document.createElement("link")
	        fileref.setAttribute("rel", "stylesheet")
	        fileref.setAttribute("type", "text/css")
	        fileref.setAttribute("href", filename)
	        if (typeof fileref != "undefined")
                document.getElementsByTagName("head")[0].appendChild(fileref)
	    }
    }

    //#endregion

}

//#region Global initializations
if (typeof _spPageContextInfo != "undefined" && _spPageContextInfo != null) {
    RegisterModuleInit(
        _spPageContextInfo.siteServerRelativeUrl + '/_catalogs/masterpage/customjavascript/SPListExtractor.core.js',
        SPListExtractor
        );

    SPListExtractor();
} else {
    _spBodyOnLoadFunctionNames.push("SPListExtractor");
}
// #endregion
